
<template>
	<view>
		<view v-if="dataBuffer">
			<view class="item"
				v-for="(res, index) in siteList" :key="res.id" 
			>	<u-icon name="close-circle-fill" :size="40" color="#ff5500" :index="res.id"></u-icon>
				<view class="top" @click="choiceAddress(index)">
					<view class="name">{{ res.username }}</view>
					<view class="phone">{{ res.userphone }}</view>
					<view class="tag">
						<text class="red" v-if="res.status == 1">默认</text>
					</view>
				</view>
				<view class="bottom" >
					{{res.location+res.useraddress}}
					<u-icon name="edit-pen" :size="40" color="#999999" :index="res.id" ></u-icon>
				</view>
			</view>
		</view>
		<view v-else>
			暂无收货地址信息!
		</view>
		<view class="addSite" @tap="toAddSite">
			<view class="add">
				<u-icon name="plus" color="#ffffff" class="icon" :size="30"></u-icon>新建收货地址
			</view>
		</view>
	</view>
</template>

<script>

export default {
	data() {
		return {
			siteList: [],//初始化地址数据
			dataBuffer:true
		};
	},
	onShow() {
		// 1.检测是否登录
		let userInfo = this.$tool.isLogin()
		if(userInfo != false){
			// 2.获取用户的收获地址数据
			this.getUserAddress(userInfo.uid)
		}
	},
	methods: {
		// 切换会员收获地址
		choiceAddress(index){
			uni.navigateTo({
				url:"../order/order?address="+JSON.stringify(this.siteList[index])
			})
		},
		// 获取会员的默认收获地址
		getUserAddress(uid){
			this.$http({
				url:"addresslist",
				data:{uid}
			})
			.then(res=>{
				// 检测是否有收获地址
				if(res.list == null){
					this.dataBuffer = false
				}else{
					this.dataBuffer = true;
					// 赋值地址数据给页面
					this.siteList = res.list
				}
			})
			.catch(err=>console.log(err))
		},
		// 跳转到新增地址页面
		toAddSite(){
			uni.navigateTo({
				url:'./addSite'
			})
		}
	}
};
</script>

<style lang="scss" scoped>
	// 引入样式
	@import  '@/static/css/address.scss';
</style>
